package aiingames.minimax;

import aiingames.minimax.State.Player;


public class Game {
	public static void main(String [] args) {
		State s1 = new State(3);

		TDTicTacToeLearner p1 = new TDTicTacToeLearner(Player.MAX);

		Minimax mm2 = new Minimax(Player.MIN);


		//System.out.println("learning" );
		double draw  = 0;
		for (int i = 0; i < 2000; i++) {
			int iter = 0;
			s1 = new State(3);
			do{
				if (iter %2 == 0) {
					s1 = p1.getTDTicTacToeLearnerDecission(s1);
				} else {
					s1 = mm2.getMinimaxDecision(s1);
				}
				iter++;
			}while(!s1.terminalTest());
			if (s1.utility() == -1) {
				p1.informAboutGameResult(s1);
			} else if (s1.utility() == 1) {
				p1.informAboutGameResult(s1);

			} else {
				p1.informAboutGameResult(s1);
				draw++;
			}
			
			if (i>0 && i % 100 == 0) {
				//System.out.println(" " + ((int)(100*(draw/100)))/100. + " ");
				draw = 0;
			}
			if (i % 10 == 0) {
				System.out.print(".");
			}
		}
		//System.out.println("done");
		//System.out.println(p1);
		


		int iter = 0;
		s1 = new State(3);
		do{
			if (iter %2 == 0) {
				s1 = p1.getTDTicTacToeLearnerDecission(s1);
			} else {
				s1 = mm2.getMinimaxDecision(s1);
			}
			//System.out.println(s1);
			iter++;
		}while(!s1.terminalTest());
	}
}
